<?php

namespace App\Admin\Controllers\Audit;

use App\Admin\Actions\Audit\AuditWithdrawAction;
use App\Admin\Grid\NGrid;
use App\Models\WithdrawModel;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Grid\Displayers\Actions;
use Encore\Admin\Grid\Filter;

class AuditWithdrawController extends AdminController
{
    protected $title = '提现审核';

    protected function grid(): NGrid
    {
        $grid = new NGrid(new WithdrawModel);
        $grid->model()->leftJoin('shop_user', 'shop_user.user_id', 'withdraw.user_id')
            ->orderByDesc('withdraw.id')->select(['withdraw.*', 'shop_user.user_mobile']);
        $grid->model()->where('withdraw.status', 0);
        $grid->filter(function (Filter $filter) {
            $filter->disableIdFilter();
            $filter->column(1 / 2, function (Filter $filter) {
                $filter->equal('withdraw-id', 'ID');
            });
            $filter->column(1 / 2, function (Filter $filter) {
                $filter->equal('withdraw-serial_number', __('l.serialNumber'));
            });
        });
        $grid->column('id', 'ID');
        $grid->column('serial_number', __('l.serialNumber'));
        $grid->column('user_mobile', __('withdraw.userMobile'));
        $grid->column('payment_method_id', __('withdraw.paymentMethodId'))->using(__('withdraw.paymentMethodIdArr'));
        $grid->column('name', __('withdraw.name'));
        $grid->column('identity', __('withdraw.identity'));
        $grid->column('amount', __('withdraw.amount'));
        $grid->column('fee', __('withdraw.fee'));
        $grid->column('created_at', __('withdraw.createdAt'));
        $grid->actions(function (Actions $actions) {
            $actions->disableEdit();
            $actions->disableDelete();
            $actions->disableView();
            $actions->add(new AuditWithdrawAction);
        });
        $grid->disableActions(false);
        return $grid;
    }
}
